/*
 * @author : TF-BJ-C064
 * @creation : 2014-6-10 下午4:28:27
 * @description : 
 *
 */

package com.service.impl;

import java.util.List;

import com.base.PageBean;
import com.bean.ParkManager;
import com.bean.Parkinfo;
import com.bean.ParkinfoManagerRelevance;
import com.dao.ParkinfoDao;
import com.tool.tmap.GPSPoint;
import com.tool.tmap.TMap;
import com.util.GUtil;

public class ParkinfoServiceImpl implements com.service.ParkinfoService {

	private ParkinfoDao dao;
	@Override
	public Object get(Integer id) throws Exception {
		return dao.findById(id);
	}

	/**
	 * <p>Title: getMyParkArea 读取我的停车场列表</p>
	 * <p>Description: </p>
	 * @param pm
	 * @return
	 * @throws Exception
	 * @see com.service.ParkinfoService#getMyParkArea(com.bean.ParkManager)
	 */
	@Override
	public List getMyParkArea(ParkManager pm) throws Exception {
		List<Parkinfo> list = dao.getMyParkArea(pm);
		return list;
	}

	@Override
	public List<Parkinfo> query(Parkinfo object, PageBean pageBeran) throws Exception {
		List<Parkinfo> list = dao.query((Parkinfo) object, pageBeran);
		if(list==null || list.size()==0)
			return null;
//		GPSPoint [] points = new GPSPoint [list.size()];
//		int i=0;
//		for(i=0; i<list.size(); i++){
//			points[i] = new GPSPoint(list.get(i).getLongitude(), list.get(i).getLatitude());
//		}
//		if(TMap.convert.GPS2BMap(points)){
//			if(list.size()!=points.length){
//				throw new Exception("坐标转换错误,转换前后不一样, points.length="+points+" array.size="+list.size());
//			}else{
//				for(i=0; i<points.length; i++){
//					list.get(i).setLongitude(points[i].getLongitude());
//					list.get(i).setLatitude(points[i].getLatitude());
//				}
//			}
//		}
		return list;
	}

	@Override
	public String add(Parkinfo pm, ParkinfoManagerRelevance pmr)
			throws Exception {
		if(dao.save(pm).equals(GUtil.SUCCESS)){
			pmr.setPId(pm.getPId());
			dao.addParkinfoManagerRelevance(pmr);
			return GUtil.SUCCESS;
		}else
			return GUtil.FAILE;
	}

	@Deprecated
	@Override
	public String add(Object object) throws Exception {
		return null;
	}

	@Override
	public String update(Object object) throws Exception {
		Parkinfo parkInfo = (Parkinfo) object;
		Parkinfo pi = (Parkinfo) this.get(parkInfo.getPId());
		if(pi==null)
			return GUtil.FAILE;
		if(parkInfo.getSource()==null)
			parkInfo.setSource((short)(1));
		parkInfo.setParkManagers(pi.getParkManagers());
		return dao.update((Parkinfo) object);
	}

	@Override
	public String delete(Integer id, Integer flag) throws Exception {
		return dao.delete(id, flag);
	}

	/**
	 * @return the dao
	 */
	public ParkinfoDao getDao() {
		return dao;
	}

	/**
	 * @param dao the dao to set
	 */
	public void setDao(ParkinfoDao dao) {
		this.dao = dao;
	}

	@Override
	public List<Object> query(Object object) throws Exception {
		return null;
	}

}
